package a1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class A04 {
    public static void main(String[] args) throws ParseException {
//        使用代码计算从出生起，活了多少天，用JDK7和JDK8两种方式实现
//        JDK7
        String birthday = "1999年1月1日";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = sdf.parse(birthday);
//        获取生日的那天的毫秒值
        long birthdayTime = date.getTime();
//        获取当前时间的毫秒值
        long nowTime = System.currentTimeMillis();
//        计算间隔了多少天
        long timeDiff = nowTime - birthdayTime;
        System.out.println(timeDiff / 1000 / 60 / 60 / 24);


//        JDK8
        LocalDate ld1 = LocalDate.of(1999,1,1);
        LocalDate ld2 = LocalDate.now();
        long days = ChronoUnit.DAYS.between(ld1,ld2);
        System.out.println(days);
    }
}
